var signAuthorize = {
    init: function() {
        var that = this;
        that.getAddress(10, '', $("select[data-name=Atprovince]"));
        that.getAddress(20, '', $("select[data-name=Atcity]"));
        that.getAddress(30, '', $("select[data-name=Attown]"));
        $.ajaxSend('api/WLCompanyBusiness/GetList?token=' + $.cookie('token'), {
            "page": 1,
            "pagesize": 20,
            "companyname": '',
            "cityid": ''
        }, function(redata) {
        		if(redata.recode=='1003'){
                window.location.href = '/nlogin.html';
                return;}
            if (redata.recode == '0000' && redata.mod.DataObj.length>0) {
                var data = redata.mod;
                var compiled = _.template($("#signAuthTpl").html());
                $("#signAuthCon").html(compiled(data));

                $("#signAuthPage").show().jqPaginator({
                    //totalPages: Math.ceil(redata.mod.TotalNum/20),
                    totalPages: redata.mod.TotalPageCount,
                    visiblePages: 5,
                    currentPage: 1,
                    first: '<li class="first"><a href="javascript:void(0);">首页<\/a><\/li>',
                    prev: '<li class="prev"><a href="javascript:void(0);"><i class="arrow arrow2"><\/i>上一页<\/a><\/li>',
                    next: '<li class="next"><a href="javascript:void(0);">下一页<i class="arrow arrow3"><\/i><\/a><\/li>',
                    last: '<li class="last"><a href="javascript:void(0);">末页<\/a><\/li>',
                    page: '<li class="page"><a href="javascript:void(0);">{{page}}<\/a><\/li>',
                    onPageChange: function(num) {
                        $("#signApplyPage").attr('curpage', num);
                        if (num != 1) {
                            that.doSearch(num);
                        }
                    }
                });

         $(".jAtNotpass").on("click", function(){
                    var apply_id=$(this).attr('apply_id');
                     $.ajax({
                            url: COMMONURL + 'api/WLCompanyBusiness/NotApply?token=' + $.cookie('token')+'&applyid='+apply_id,
                            type: 'post',
                            dataType: 'json',
                            data: {
                            }
                        }).done(function(data){
                            if(redata.recode == '0000'){
                            alert('操作成功');
                            window.location.reload();
                          }
                        })
                })

                $(".jAtpass").on("click", function(){
                    var wuliu_id = $(this).attr('wuliu_id'),
                        wuliu_no = $(this).attr('wuliu_no'),
                        wuliu_name = $(this).attr('wuliu_name'),
                       apply_id=$(this).attr('apply_id');
                     company_id=$(this).attr('company_id');
                      company_no=$(this).attr('company_no');
                       company_name=$(this).attr('company_name');
                     $.ajax({
                            url: COMMONURL + 'api/WLCompanyBusiness/UpdateApply?token=' + $.cookie('token'),
                            type: 'post',
                            dataType: 'json',
                            data: {
                                wuliu_id:wuliu_id,
                                wuliu_no: wuliu_no,
                                wuliu_name: wuliu_name,
                                apply_flag:'20',
                                id:apply_id,
                                company_id:company_id,
                                company_no:company_no,
                                company_name:company_name
                            }

                        }).done(function(data){
                            if(redata.recode == '0000'){
                            alert('操作成功');
                           
                            window.location.reload();
                          }
                        })
                })
            }else{
                var data = redata.mod;
                var compiled = _.template($("#signAuthTpl").html());
                $("#signAuthCon").html(compiled(data));
            }
        });
        
         /*$(".jAtNotpass").on("click", function(){
                    var apply_id=$(this).attr('apply_id');
                     $.ajax({
                            url: COMMONURL + 'api/WLCompanyBusiness/NotApply?token=' + $.cookie('token'),
                            type: 'post',
                            dataType: 'json',
                            data: {
                                id:apply_id
                            }

                        }).done(function(data){
                            if(redata.recode == '0000'){
                            alert('操作成功');
                           
                            window.location.reload();
                          }
                        })
                })
            }else{
                var data = redata.mod;
                var compiled = _.template($("#signAuthTpl").html());
                $("#signAuthCon").html(compiled(data));
            }
        });*/

        $("#signAuthQuery").click(function() {
            that.doSearch();
        });
    },
    getAddress: function(type, sub, obj) {
        $.ajax({
            url: COMMONURL + 'api/CityBase/GetCityBaseList?token=' + $.cookie('token'),
            type: 'post',
            dataType: 'json',
            data: {
                type: type,
                sub_city_id: sub
            }

        }).done(function(data) {
            var arry = [];
            if (!!data.mod) {
                if (!data.mod.length) {
                    arry.push('<option value="' + '" data-id="' + '">' + '请选择' + '</option>');
                } else {
                    $.each(data.mod, function(i, v) {
                        arry.push('<option value="' + v.city_name + '" data-id="' + v.city_id + '">' + v.city_name + '</option>');
                    });
                }
                obj.html(arry.join(''));
            }

        })
    },
    doSearch: function() {
        $.ajax({
            url: COMMONURL + "api/WLCompanyBusiness/GetList?token=" + $.cookie('token'),
            type: "post",
            data: {
                page: page,
                pagesize: 20,
                companyname: Company,
                cityid: cityid
            },
            dataType: "json"
        }).done(function(redata) {
        		if(redata.recode=='1003'){
                window.location.href = '/nlogin.html';
                return;}
            if (redata.recode == '0000') {
                var compiled = _.template($("#signAuthTpl").html());
                var odata = redata.mod.DataObj;
                $("#signAuthCon").html(compiled(redata.mod));
            }
        });

    }
}


signAuthorize.init();
